/*****************************************************************************/
/**
 *	\file	initialRoom.cpp
 *	\author	Xavier
 *	\date	2023/05/07
 *	\version	1.0
 *	\brief	房间信息初始化
 *	\note	Copyright (c) 2020-2030 南京理工大学
 *	\remarks	无
 ******************************************************************************/
#include "head.h"

int fibonaci(int i)
{
    if (i == 0)
    {
        return 0;
    }
    if (i == 1)
    {
        return 1;
    }
    return fibonaci(i - 1) + fibonaci(i - 2);
}

int fibonaci(char a)
{
    int i = a - '0';
    return fibonaci(i);
}

template <typename T>
T Max(T a, T b)
{
    return a > b ? a : b;
}

int sum(int count, ...)
{
    va_list args;
    int sum = 0;
    va_start(args, count);
    for (int i = 0; i < count; i++)
    {
        sum += va_arg(args, int);
    }
    va_end(args);
    return sum;
}

void initialRoom(CMgr *mgrobj)
{ // 对80个房间进行初始化,分4个等级
    assert(NULL != mgrobj);
    int j, k = sum(2, 600, 1);
    for (j = 0; j < 20; j++)
    {
        mgrobj->room[j].number = k++;
        mgrobj->room[j].dank = fibonaci(2);
        mgrobj->room[j].price = Max(140, 150);
        mgrobj->room[j].state = 0;
    }
    k = sum(2, 600, 101);
    for (j = 20; j < 40; j++)
    {
        mgrobj->room[j].number = k++;
        mgrobj->room[j].dank = fibonaci(3);
        mgrobj->room[j].price = 200;
        mgrobj->room[j].state = 0;
    }
    k = sum(3, 600, 100, 101);
    for (j = 40; j < 60; j++)
    {
        mgrobj->room[j].number = k++;
        mgrobj->room[j].dank = fibonaci(4);
        mgrobj->room[j].price = 300;
        mgrobj->room[j].state = 0;
    }
    k = sum(4, 200, 200, 200, 301);
    for (j = 60; j < 80; j++)
    {
        mgrobj->room[j].number = k++;
        mgrobj->room[j].dank = 2 * fibonaci(3);
        mgrobj->room[j].price = 600;
        mgrobj->room[j].state = 0;
    }
}